package com.atguigu.controller;

import com.atguigu.base.BaseController;
import com.atguigu.entity.HouseUser;
import com.atguigu.service.HouseUserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author:hx
 * @DateTime:2022/9/28 14:12
 * @Description:
 */
@Controller
@RequestMapping("/houseUser")
public class HouseUserController extends BaseController {
    @DubboReference
    private HouseUserService houseUserService;

    @RequestMapping("/create")
    public String create(){
        return "houseUser/create";
    }

    @RequestMapping("/save")
    public String insert(Model model,HouseUser houseUser){
        houseUserService.insert(houseUser);
        return successPage(model,"添加房东信息成功!");
    }

    @RequestMapping("/edit/{id}")
    public String edit(Model model,@PathVariable Long id){
        HouseUser houseUser = houseUserService.getById(id);
        model.addAttribute("houseUser",houseUser);
        return "houseUser/edit";
    }

    @RequestMapping("/update")
    public String update(Model model,HouseUser houseUser){
        houseUserService.update(houseUser);
        return successPage(model,"修改房东信息成功!");
    }

    @RequestMapping("/delete/{houseId}/{id}")
    public String delete(@PathVariable("houseId") Long houseId,@PathVariable("id") Long id){
        houseUserService.delete(id);
        return "redirect:/house/"+houseId;
    }
}
